<?php
namespace app\admin\model;
use think\Loader;
use think\Model;
use think\Validate;

class ConfigModel extends Model
{
    protected $pk = 'id';//主键
    //设置当前模型对应的完整数据表名称
    protected $table = 'fly_config';
    //全部系统配置
    public function configList()
    {
    	$configList = $this->select();
    	return $configList;
    }
    //返回站点名
    public function web_name()
    {
        $web_name = $this->where('config_name', 'web_name')->find();
        return $web_name->data;
    }
     public function record_number()
    {
        $record_number = $this->where('config_name', 'record_number')->find();
        return $record_number->data;
    }
     public function zz_email()
    {
        $zz_email = $this->where('config_name', 'zz_email')->find();
        return $zz_email->data;
    }

     public function web_keywords()
    {
        $web_keywords = $this->where('config_name', 'web_keywords')->find();
        return $web_keywords->data;
    }
     public function web_description()
    {
        $web_description = $this->where('config_name', 'web_description')->find();
        return $web_description->data;
    }
     public function qq_id()
    {
        $qq_id = $this->where('config_name', 'qq_id')->find();
        return $qq_id->data;
    }
     public function qq_key()
    {
        $qq_key = $this->where('config_name', 'qq_key')->find();
        return $qq_key->data;
    }
     public function baidu_site()
    {
        $baidu_site = $this->where('config_name', 'baidu_site')->find();
        return $baidu_site->data;
    }
     public function statistics()
    {
        $statistics = $this->where('config_name', 'statistics')->find();
        return $statistics->data;
    }
     public function email_smtp()
    {
        $email_smtp = $this->where('config_name', 'email_smtp')->find();
        return $email_smtp->data;
    }
     public function email_name()
    {
        $email_name = $this->where('config_name', 'email_name')->find();
        return $email_name->data;
    }
     public function email_pwd()
    {
        $email_pwd = $this->where('config_name', 'email_pwd')->find();
        return $email_pwd->data;
    }
     public function email_nickname()
    {
        $email_nickname = $this->where('config_name', 'email_nickname')->find();
        return $email_nickname->data;
    }
    //修改网站设置setup1
    public function setup1($data){
        //更新
        $list = [
            ['id'=>2,'config_name'=>'record_number','config_val'=>$data['record_number']],
            ['id'=>3,'config_name'=>'zz_email','config_val'=>$data['zz_email']]
        ];
        $res = $this->saveAll($list);

        if($res){
            return ['valid'=>1, 'msg'=>'修改成功'];
        }else{
            return ['valid'=>0, 'msg'=>'修改失败'];
        }
    }
    //修改网站设置setup2
    public function setup2($data){
        //更新
        $list = [
            ['id'=>1,'config_name'=>'web_name','config_val'=>$data['web_name']],
            ['id'=>4,'config_name'=>'web_keywords','config_val'=>$data['web_keywords']],
            ['id'=>5,'config_name'=>'web_description','config_val'=>$data['web_description']]
        ];
        $res = $this->saveAll($list);

        if($res){
            return ['valid'=>1, 'msg'=>'修改成功'];
        }else{
            return ['valid'=>0, 'msg'=>'修改失败'];
        }
    }
    //修改网站设置setup3
    public function setup3($data){
        //更新
        $list = [
            ['id'=>6,'config_name'=>'qq_id','config_val'=>$data['qq_id']],
            ['id'=>7,'config_name'=>'qq_key','config_val'=>$data['qq_key']]
        ];
        $res = $this->saveAll($list);

        if($res){
            return ['valid'=>1, 'msg'=>'修改成功'];
        }else{
            return ['valid'=>0, 'msg'=>'修改失败'];
        }
    }
    //修改网站设置setup4
    public function setup4($data){
        //更新
        $list = [
            ['id'=>8,'config_name'=>'baidu_site','config_val'=>$data['baidu_site']],
            ['id'=>9,'config_name'=>'statistics','config_val'=>$data['statistics']]
        ];
        $res = $this->saveAll($list);

        if($res){
            return ['valid'=>1, 'msg'=>'修改成功'];
        }else{
            return ['valid'=>0, 'msg'=>'修改失败'];
        }
    }
    //修改网站设置setup5
    public function setup5($data){
        //更新
        // dump($data);die;
        $list = [
            ['id'=>10,'config_name'=>'email_smtp','config_val'=>$data['email_smtp']],
            ['id'=>11,'config_name'=>'email_name','config_val'=>$data['email_name']],
            ['id'=>12,'config_name'=>'email_pwd','config_val'=>$data['email_pwd']],
            ['id'=>13,'config_name'=>'email_nickname','config_val'=>$data['email_nickname']]
        ];
        $res = $this->saveAll($list);

        if($res){
            return ['valid'=>1, 'msg'=>'修改成功'];
        }else{
            return ['valid'=>0, 'msg'=>'修改失败'];
        }
    }


}